package org.proddevplm.dao.util;

import org.proddevplm.constants.UserConstants;
import org.proddevplm.dao.data.User;
import org.proddevplm.dao.data.productFollowUp.productionPhase.ManufacturingItinerary;
import org.proddevplm.dao.data.productFollowUp.productionPhase.Process;
import org.proddevplm.dao.data.productFollowUp.usePhase.Complaints;
import org.proddevplm.dao.data.productFollowUp.usePhase.Suggestions;

import java.util.Date;
import java.util.Map;

import javax.servlet.http.HttpSession;


public class EntityBuilder {

    public static Object buildEntity(String type, Map parameters, HttpSession session) {
        Object entity = null;
        User user = (User) session.getAttribute(UserConstants.USER);
        
        if ("guestIssueUpload".equals(type)) {
            Complaints complaint = new Complaints();
            
            complaint.setProductId(Integer.valueOf(parameters.get("issueProductId").toString()));
            complaint.setUniqueId(String.valueOf(parameters.get("uniqueId")));
            complaint.setType(String.valueOf(parameters.get("problemType")));
            complaint.setDescription(String.valueOf(parameters.get("problemDescription")));
            complaint.setFilePath(String.valueOf(parameters.get("filePath")));
            complaint.setAuthor(user.getSurname()+" "+user.getName());
            complaint.setEmail(user.getEmail());
            complaint.setDate(new Date().toString());
            entity = complaint;
        
        }else if ("guestFunctionUpload".equals(type)){
        	Suggestions suggestion = new Suggestions();
        	
        	suggestion.setProductId(Integer.valueOf(parameters.get("functionsProductId").toString()));
        	suggestion.setDescription(String.valueOf(parameters.get("functionDescription")));
        	suggestion.setFilePath(String.valueOf(parameters.get("filePath")));
        	suggestion.setAuthor(user.getSurname()+" "+user.getName());
        	suggestion.setDate(new Date().toString());
        	suggestion.setEmail(user.getEmail());
        	
        	entity = suggestion;
        	
        }else if("manufItinerary".equals(type)){
        	ManufacturingItinerary itinerary = new ManufacturingItinerary();
        	
        	itinerary.setProductId(Integer.valueOf(session.getAttribute("productId").toString()));
        	itinerary.setDescription(String.valueOf(parameters.get("itineraryDescription")));
        	itinerary.setFilePath(String.valueOf(parameters.get("filePath")));
        	itinerary.setAuthor(user.getSurname()+" "+user.getName());
        	itinerary.setDate(new Date().toString());
        	
        	entity = itinerary;
        	
        }else if("process".equals(type)){
        	Process process = new Process();
        	
        	process.setProductId(Integer.valueOf(session.getAttribute("productId").toString()));
        	process.setProcessName(String.valueOf(parameters.get("processName")));
        	process.setProcessDescription(String.valueOf(parameters.get("processDescription")));
        	process.setFilePath(String.valueOf(parameters.get("filePath")));
        	process.setAuthor(user.getSurname()+" "+user.getName());
        	process.setDate(new Date().toString());
        	
        	entity = process;
        	
        }

        return entity;
    }

}
